home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
boxdraw.exe
/
BOXDRAW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-09
|
4KB
|
139 lines
/* remove this #define to use as a function in a program */
#define DEMO
/*
* boxdraw - Copyright 1992, Edward Mulroy
* Authorized for private and commercial use
*
* This is designed for use with TC++, BC++ and TC 2.0
* It may be compiled as C or C++
*/
#include <conio.h>
#include "boxdraw.h"
typedef enum
{
UpLeft, Horiz, UpRight, Vert, LowLeft, LowRight
} box_index;
static char dble_box[] = "\xC9\xCD\xBB\xBA\xC8\xBC"; /* "╔═╗║╚╝" */
static char sngle_box[] = "\xDA\xC4\xBF\xB3\xC0\xD9"; /* "┌─┐│└┘" */
/*
* Draws a box with the corners given
* [x1,y1] is the upper left corner of the box
* [1,1] is the upper left corner of the screen
* "box_type" is 0 for a single line box, 1 for a double
* The box is drawn in the default color
*
* Return values are:
* 0=success -1=invalid box_type -2=invalid co-ordinates
*/
int draw_box( int x1, int y1, int x2, int y2, int box_type)
{
struct text_info ti;
char line[ 133];
int ix,iy, istop;
char *draw_ptr;
char ch;
#ifdef _NOCURSOR /* TC 2.0 did not have _wscroll or _setcursortype() */
int old_wscroll = _wscroll; /* the 1st edition of TC++ did not have */
/* _wscroll declared, even 'though it was */
/* in there. If that's the case with you */
/* put extern int _wscroll; at the top */
_setcursortype( _NOCURSOR);
#endif
if ( box_type == single_border) /* decide on which box type */
draw_ptr = sngle_box; /* array to draw with */
else if ( box_type == double_border)
draw_ptr = dble_box;
else
return -1; /* indicate invalid box type */
gettextinfo( &ti); /* capture current screen, window and cursor info */
if ( ((x2 - x1) < 2) || ((y2 - y1) < 2) || (x1 < ti.winleft) ||
(y1 < ti.wintop) || (x2 > ti.winright) || (y2 > ti.winbottom))
return -2; /* indicate invalid box co-ordinates */
/* make up a string containing the horizontal line for the top & bottom */
for ( istop = (x2 - x1 - 1), ix = 0, ch = draw_ptr[ Horiz]; ix < istop; ix++)
line[ ix] = ch;
line[ ix] = '\0'; /* terminate the string */
window( 1, 1, ti.screenwidth, ti.screenheight); /* use full-screen co-ord's */
gotoxy( x1, y1); /* draw the top */
putch( *draw_ptr);
cputs( line);
putch( draw_ptr[ UpRight]);
gotoxy( x1, y2); /* draw the bottom */
putch( draw_ptr[ LowLeft]);
cputs( line);
putch( draw_ptr[ LowRight]);
for ( ch = draw_ptr[ Vert], iy = y1 + 1; iy < y2; iy++) /* draw the sides */
{
gotoxy( x1, iy);
putch( ch);
gotoxy( x2, iy);
putch( ch);
}
/* restore the old window and cursor position */
window( ti.winleft, ti.wintop, ti.winright, ti.winbottom);
gotoxy( ti.curx, ti.cury);
#ifdef _NORMALCURSOR
_setcursortype( _NORMALCURSOR);
_wscroll = old_wscroll;
#endif
return 0; /* return a value to indicate success */
}
#ifdef DEMO
int main()
{
int i;
clrscr();
/* write the col and row numbers around one of the boxes */
for ( i = 10; i < 60; i += 10)
{
gotoxy( i, 1);
putch( (i / 10) + '0');
}
gotoxy( 5,2);
for ( i = 5; i < 51; i++)
putch( (i % 10) + '0');
for ( i = 3; i <= 15; i++)
{
gotoxy( 51, i);
cprintf( "%2d", i);
}
draw_box( 10, 20, 70, 23, double_border); /* draw two boxes */
draw_box( 5, 3, 50, 15, single_border);
return 0;
}
#endif